package com.wangxinrou.wangxinrou_surprisemeal.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wangxinrou.wangxinrou_surprisemeal.mapper.PreferenceMapper;
import com.wangxinrou.wangxinrou_surprisemeal.model.Preference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PreferenceService {
    @Autowired
    private PreferenceMapper preferenceMapper;

    // 获取所有偏好
    public List<Preference> getAllPreferences() {
        return preferenceMapper.selectList(null);
    }

    // 根据用户ID获取偏好
    public List<Preference> getPreferencesByUserId(int userId) {
        return preferenceMapper.selectList(new QueryWrapper<Preference>().eq("user_id", userId));
    }

    // 添加偏好
    public boolean addPreference(Preference preference) {
        return preferenceMapper.insert(preference) > 0;
    }

    // 更新偏好
    public boolean updatePreference(Preference preference) {
        return preferenceMapper.updateById(preference) > 0;
    }

    // 根据ID删除偏好
    public boolean deletePreference(int prefId) {
        return preferenceMapper.deleteById(prefId) > 0;
    }
}
